﻿<?php
/**
 * 管理用户代码
 * @author kinet <380511703@qq.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */

session_start();
require_once( 'path.php');
require_once( SOJ_ROOT.'/include/function/lib.php');

$tpl = new my_smarty();

//若未登录,则重定向到登录界面
if( empty($_SESSION['admin']) ){

	$_SESSION['success_message'] = 'do not login yet , '.$_SESSION['admin'];
	header( 'Location:../manager/manager_login.php' );
	exit ;
}
$request = $_GET;

if( empty( $request['jno'])||empty($request['username'])||empty($request['file']) ){
	//problem,直接跳转到problem页面
	header( 'Location:../manager/manager_index.php');
	exit ;
}else{
	$no = $request['jno'];
	$username=$request['username'];
	$code_file_name=$request['file'];
}


//处理由其他页面保存在会话中的错误信息
if( !empty($_SESSION['errors']) ){

	$tpl->assign( 'errors' , $_SESSION['errors']  );
	//清除之前的错误信息
	unset( $_SESSION['errors'] );
}
$tpl->assign('admin', $_SESSION['admin']);


try{
	  $db = db_connect();	 
	  $code=new code_process($db); 
	  $code->load('code_file_name',$code_file_name);
	  $problem_no=$code->get_problem_no();
      $language=$code->get_language();
      $modify_time=$code->get_modify_time();
      $create_time=$code->get_create_time();
      $time_limit=$code->get_time_limit();
      $mem_limit=$code->get_mem_limit();
      $content=$code->get_content(); 
      $tpl->assign('judge_no',$no);
      $tpl->assign('username',$username);
      $tpl->assign('filename',$code_file_name);	  
	  $tpl->assign('problem_no', $problem_no);
	  $tpl->assign('language',$language);
	  $tpl->assign('modify_time',$modify_time);
	  $tpl->assign('create_time', $create_time);
	  $tpl->assign('time_limit', $time_limit);
	  $tpl->assign('mem_limit', $mem_limit);
	  $tpl->assign('content',  $content);
	  $tpl->display('manager_user_code_file.tpl');

}catch(Exception $e){
	  echo $e->getMessage();
}
